/**
 * 
 */
package com.nari.basic.utils.struts2tags;

import org.apache.struts2.util.SubsetIteratorFilter.Decider;

import com.nari.basic.model.IMenu;

/**
 * 自定义Struts2标签subset过滤菜单列表子集时的过滤策略
 * @author Xiaopeng
 * @date 2013-8-4
 */
public class MenuFilterDecider implements Decider {
	private String parentMenuID;

	public boolean decide(Object element) throws Exception {
		IMenu menu = (IMenu) element;
		//若父菜单ID不存在，则返回一级菜单
		if(parentMenuID==null || "".equals(parentMenuID.trim())) {
			if(menu.getParentID()==null || "".equals(menu.getParentID().trim())) return true;
		} else { //根据父菜单ID过滤子菜单
			if(menu.getParentID()!=null && !"".equals(menu.getParentID().trim())) {
				if(parentMenuID.trim().equals(menu.getParentID().trim())) return true;
			}
		}
		return false;
	}

	/**
	 * @return the parentMenuID
	 */
	public String getParentMenuID() {
		return parentMenuID;
	}

	/**
	 * @param parentMenuID the parentMenuID to set
	 */
	public void setParentMenuID(String parentMenuID) {
		this.parentMenuID = parentMenuID;
	}

}
